﻿using Member.Domain.Entities;
using Member.Domain.IRepository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Member.Domain.Services
{
    public class AdminUserService
    {
        private readonly IAdminUserRepository _adminUserRepository;
        public AdminUserService(IAdminUserRepository adminUserRepository)
        {
            _adminUserRepository = adminUserRepository;
        }
        /// <summary>
        /// 登录获取用户信息
        /// </summary>
        /// <param name="loginname"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task<AdminUser> GetAdminUserByPasswordAsync(string phone, string passWord)
        {
            AdminUser adminUser = new AdminUser();
            if (adminUser.isSuperAdmin(phone, passWord))
            {
                adminUser.CreateSuperAdmin(phone);
            }
            else
            {
                adminUser.SetMd5Pwd(passWord);
                adminUser = await _adminUserRepository.GetEntityByPasswordAsync(phone, adminUser.password);
            }
            return adminUser;
        }

        public async Task<List<AdminUser>> GetAdminUserPageListAsync(RefAsync<int> totalConut, int page, int limit) 
        {
            return await _adminUserRepository.GetPageListAsync(totalConut, page, limit);
        }
    }
}
